package 面向对象.实验10;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

/**
 * @author IT_Jay
 * @date 2021/12/16 10:04 AM
 */
public class Test01 {
    public static void main(String[] args) throws IOException {
        //创建一个具有服务器IP地址和端口号的Socket对象
        Socket soc=new Socket("localhost",4001);

        //客户端接受输入
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("请输入消息至服务器，输入send发送。");
        String message="";
        String temp;
        while(!(temp=br.readLine()).equals("send")){
            message=message+temp+"\n";
        }

        //客户端向服务器发送请求。
        PrintStream ps=new PrintStream(soc.getOutputStream());
        ps.print(message);

        //关闭PrintStream和Socket对象
        ps.close();
        soc.close();
    }
}
